< previous page page_374 next page >

Page 374
note.gif Built-in collections may not necessarily contain all of the following properties and methods. square.gif

Table 16.2 Properties and Methods Common to All Collections
ItemUse To
Count propertyReport the number of objects in a collection
Item methodGet a single object from a collection

In addition to the items in Table 16.2, collections usually provide two more methods. The methods in Table 16.3 are common to most collections.
Table 16.3 Methods Common to Most Collections
MethodPurpose
AddAdd an object to a collection
RemoveDelete an object from a collection

The Add and Remove methods provide programmers a standard way to create and delete items in a collection. The Visual Basic Forms and Controls collections are maintained by Visual Basic, so they don't support these methods. The Add method usually includes key and index parameters, used to identify an object in a collection. However, Add and Remove may be implemented differently for different types of collections. For example, compare the Add syntax for the ListView control's ListItems collection and the ListImages collection of an image list:
ListView1.ListItems.Add index,key,text,IconNumber,smallIconNumber
ImageList1.ListImages.Add index,key,picture
Creating a New Collection for Grouped Actions
You can create collections to contain forms, controls, and objects. Use the Collection object data type when creating a new collection. The following declaration creates a new collection named colSelected:
Dim colSelected As New Collection
Declaring a variable as a Collection object gives you four built-in properties and methods, as shown in Table 16.4.

 
< previous page page_374 next page >